package s7

type ClientApi interface {
	// ReadBool 读取点位上的bool值
	ReadBool(point string) (bool, error)
	// ReadFloat32 读取指定点位的32位浮点数
	ReadFloat32(p string) (float32, error)
	// ReadInt16 读取指定点位的16位整数
	ReadInt16(p string) (int16, error)
	// ReadInt32 读取指定点位的32位整数
	ReadInt32(p string) (int32, error)
	ReadInt8(p string) (int8, error)
	ReadString(p string, size int) (string, error)
	ReadUint16(p string) (uint16, error)
	ReadUint32(p string) (uint32, error)
	ReadUint8(p string) (uint8, error)
	// ReadBytes 从指定点位开始的读取count个字节
	ReadBytes(p string, count int) ([]byte, error)
	// ReadWString 读取双字节字符
	ReadWString(p string, size int) (string, error)
	WriteBool(p string, v bool) error
	WriteFloat(p string, v float32) error
	WriteInt16(p string, v int16) error
	WriteInt32(p string, v int32) error
	WriteInt8(p string, v int8) error
	WriteString(p string, v string) error
	WriteUint16(p string, v uint16) error
	WriteUint8(p string, v uint8) error
	WriteUint32(p string, v uint32) error
	// WriteBytes  从指定点位开始写入数据
	WriteBytes(p string, data []byte) error
	//WriteWString 写入宽(双字节)字符
	WriteWString(p string, value string) error
}

// NewS7Service 创建新的S7链接对象
// 参数说明:
//
//	ipAddr	:设备地址
//	port	:链接端口
//	rack	:设备曹号默认0
//	slot	:设备卡默认1
//
// 返回
//
//	 *Client 连接对象
//		error:nil表示连接成功
func NewS7Service(ipAddr string, port int, rack int, slot int) (*Client, error) {
	service := Client{
		ipAddr: ipAddr,
		port:   port,
		rack:   rack,
		slot:   slot,
	}
	err := service.Open()
	if nil != err {
		return nil, err
	}
	return &service, nil
}

// NewS7ServiceEx 创建S7连接对象
func NewS7ServiceEx(ip string, port int) (*Client, error) {
	return NewS7Service(ip, port, 0, 1)
}
